import axios from 'axios'

const api = {
  getNotice: {
    url: 'https://run.mocky.io/v3/77faa2d0-e4be-4e91-9642-e48af8d05184',
    methods: 'get'
  }
}

function req(funcName, data){
  const request = api[funcName]
  if (toString.call(request) === '[object Undefined]') {
    throw new Error('调用api函数错误，请检查函数名称是否错误')
  }
  const reqConfig = {
    ...request,
    headers: {
      'Content-Type': 'application/json'
    },
  }
  data && (reqConfig.data = data)
  return axios(reqConfig)
}

export default req